﻿@using QuestionsAnswers.UI.Models
@model IEnumerable<Answer>
@{bool userHasAnswered = false;}
@if (Model.Any())
{
    <table>
        <tr>
            <th>
                Rate
            </th>
            <th>
                Text
            </th>
            <th>
                Comment
            </th>
        </tr>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.Partial("RatingsPartial", new RateModel { Id = item.AnswerId, Type = "Answer", ReturnUrl = Request.Url.ToString() })
                </td>
                 <td style=" text-align: left">
                    @Html.DisplayFor(modelItem => item.Text)
                <div style="text-align: right">
                    @Html.DisplayFor(modelItem => item.User.UserName)|
                                 
                
                    @if (User.Identity.Name == item.User.UserName)
                    {

                        { userHasAnswered = true; }
                        
                        @Ajax.ActionLink("Edit", "Edit", "Answer", new { id = item.AnswerId }, new AjaxOptions { OnSuccess = "OnSuccessGeneral" })
                        @:|
                        @Html.ConfirmLink("Delete", "Answer", "Delete", new { id = item.AnswerId }, "Really Delete?")                  
                    }
                    </div>
                </td>
            <td>
               @Html.ActionLink("Comments", "Index", "Comment", new { id = item.AnswerId }, "")</td>
     
            </tr>
        }
    </table>
    
}
@if (ViewData["QuestionId"] != null)
{
    @Ajax.ActionLink("Add Answer", "Create", "Answer", new { id = ViewData["QuestionId"] }, new AjaxOptions { OnSuccess = "OnSuccessGeneral" }, new { style = "text-align:left" })
}